package org.jeecg.modules.deepseek.controller;

import org.jeecg.common.api.vo.Result;
import org.jeecg.config.shiro.IgnoreAuth;
import org.jeecg.modules.deepseek.pojo.ChatRequest;
import org.jeecg.modules.deepseek.pojo.ChatRequestExample;
import org.jeecg.modules.deepseek.pojo.MatchRequest;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/deepseek")
@RestController
@CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.POST})
public class MatchController {



    @PostMapping("/match")
    @IgnoreAuth
    public Result<String> submitForm(@ModelAttribute MatchRequest matchRequest) {

        ChatRequest.Message system = new ChatRequest.Message("system", "你是一个留学选校系统，请根据对方的学校，地区，GPA，目标专业等信息，为用户推荐合适的院校,请格式化输出内容到html的<body>标签中");
        ChatRequest.Message user = new ChatRequest.Message("user", "我的学校：" + matchRequest.getMySchool()+ "，地区：" + matchRequest.getTargetRegion()+ "，GPA：" + matchRequest.getGpa()+ "，目标专业：" + matchRequest.getTargetMajor());
        // 这里可以调用服务类进行院校匹配的逻辑处理

        ResponseEntity<OpenAiApi.ChatCompletion>
                chatCompletionChunkResponseEntity1 = ChatRequestExample.requestDeepSeekChat(null, List.of(
                system,
                user
        ));
        String content = null;
        try {
            content = chatCompletionChunkResponseEntity1.getBody().choices().get(0).message().content();
            System.out.println("content = " + content);
        } catch (Exception e) {
            return Result.error("匹配失败，请稍后再试");
        }

        return Result.okGPT(content);
    }
}
